$(function () {
   layui.use(['form','laytpl'],function () {
       var form = layui.form(),
        laytpl = layui.laytpl;

       //渲染供应商名称选择框数据
       var data = [
               {"value":"1","name":"供应商1"},
               {"value":"2","name":"供应商2"},
               {"value":"3","name":"供应商3"},
           ];

       //异步请求获取供应商名称选择框数据data
       $.post('', data, function (response) {
           if (response.code == 0) {

           } else {
               layer.msg(response.msg,{icon: 2});
           }
       }, 'json');

       var getTpl = select.innerHTML,
           view1 = document.getElementById('supplierName');
       laytpl(getTpl).render(data, function (html) {
           view1.innerHTML = html;
           form.render('select');  //重点重新渲染
       });

       //渲染供应商类别选择框数据
       var data2 = [
               {"value":"1","name":"客户指定供应商"},
               {"value":"2","name":"国内供应商及CM厂"},
               {"value":"3","name":"海外供应商"},
               {"value":"4","name":"代理商/贸易商"}
           ];
       var view2 = document.getElementById('supplierType');
       laytpl(getTpl).render(data2, function (html) {
           view2.innerHTML = html;
           form.render('select');  //重点重新渲染
       });

       //渲染赔偿类别选择框数据
       var data3 = [
               {"value":"1","name":"来料检验阶段异常"},
               {"value":"2","name":"在制阶段异常"},
               {"value":"3","name":"客户端发现异常"},
               {"value":"4","name":"其它异常"},
               {"value":"5","name":"其它"}
           ];
       var view3 = document.getElementById('compensationType');
       laytpl(getTpl).render(data3, function (html) {
           view3.innerHTML = html;
           form.render('select');  //重点重新渲染
       });

       //渲染处罚项目选择框数据
       var data4 = [
               {"value":"1","name":"赔偿"},
               {"value":"2","name":"延长付款周期"},
               {"value":"3","name":"减少采购订单量或者取消在途订单"},
               {"value":"4","name":"暂停采购"},
               {"value":"5","name":"转为临时供应商"},
               {"value":"6","name":"转为不合格供应商"},
               {"value":"7","name":"其他"}
           ];
       var view4 = document.getElementById('penaltyItem');
       laytpl(getTpl).render(data4, function (html) {
          view4.innerHTML = html;
          form.render('select');  //重点重新渲染
       });

       //渲染赔付实施时间
       var data5 = [
               {"value":"1","name":"分段实施"},
               {"value":"2","name":"一次性实施"}
           ];
       var view5 = document.getElementById('penaltyTime');
       laytpl(getTpl).render(data5, function (html) {
           view5.innerHTML = html;
           form.render('select');  //重点重新渲染
       });

       //渲染赔付支付方式
       var data6 =[
               {"value":"1","name":"贷款中扣除"},
               {"value":"2","name":"电汇支付"},
               {"value":"3","name":"其他"}
           ];
       var view6 = document.getElementById('penaltyWay');
       laytpl(getTpl).render(data6, function (html) {
           view6.innerHTML = html;
           form.render('select');  //重点重新渲染
       });

       //监听供应商名称的选择，将其代码直接放到供应商代码的input框中
       form.on('select(supplierName)', function (data) {
           //选中赋值
           $('.supplierCode').val(data.value);
       });
       
       //监听处罚项目选择，如果是赔偿，需指定描述内容
       form.on('select(penaltyItem)', function (data) {
           if (data.value == "1") {
               var text = "赔偿总金额：\r\n实际执行金额：\r\n实际执行金额大写：";  //\r\n表示换行
               $('.penaltyDescription').val(text);  //赋值
               $('.pay').show();  //出现付款时间和方式选择项
           } else {
               $('.penaltyDescription').val("");
               $('.pay').hide();
           }
       });

       
       //监听发起评审
       form.on('submit(review)', function (data) {
           console.log(data.field);
           return false;//阻止跳转
       })

   })
});